home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 1997
/
MacHack 1997.toast
/
Other Stuff
/
Other Stuff ’97
/
PowerOS Development
/
basic kernel source
/
debug_video.c
< prev
next >
Wrap
C/C++ Source or Header
|
1997-06-26
|
3KB
|
130 lines
/*
debug_video.c
a source file for PowerOS
copyright 1996-1997 by Ben Martz
all rights reserved world wide
ANY AND ALL MODIFICATIONS TO THIS SOURCE MUST CREDIT THE ORIGINAL
AUTHOR, BEN MARTZ (benmartz@ic.net), AND MUST BE GIVEN TO THE AUTHOR
FOR INTEGRATION INTO THE MAIN PowerOS SOURCE TREE. THANK YOU FOR YOUR
COOPERATION!
*/
#include "poweros_types.h"
#include "debug_video.h"
#include "debug_console.h"
VideoPrivateData videoPrivate;
void vinit(char *baseaddr, short rowbytes, short depth, short width, short height) {
short h,v;
long backcolor;
videoPrivate.baseaddr = baseaddr;
videoPrivate.rowbytes = rowbytes;
videoPrivate.depth = depth;
videoPrivate.width = width;
videoPrivate.height = height;
/* this clears the screen with a kind of venitian blind effect */
if(depth > 8) backcolor = 0L;
else backcolor = 0xFFFFFFFF;
for(v = 0; v < videoPrivate.height; v+=4)
for(h = 0; h < videoPrivate.width; h++)
vputpixel(h,v,backcolor);
for(v = 1; v < videoPrivate.height; v+=4)
for(h = 0; h < videoPrivate.width; h++)
vputpixel(h,v,backcolor);
for(v = 2; v < videoPrivate.height; v+=4)
for(h = 0; h < videoPrivate.width; h++)
vputpixel(h,v,backcolor);
for(v = 3; v < videoPrivate.height; v+=4)
for(h = 0; h < videoPrivate.width; h++)
vputpixel(h,v,backcolor);
}
void vputpixel(short h, short v, u_long value) {
char *rowbase;
if((h < 0) || (h > videoPrivate.width) || (v < 0) || (v > videoPrivate.height))
return;
/* set the pixel location ptr */
rowbase = videoPrivate.baseaddr;
rowbase += v * videoPrivate.rowbytes;
/*
when we have time, we should make a global variable that points
to a pixel drawing routine for a particular depth, so that the
variable is assigned at boot time and whenever the video mode
is changed, so that all drawing in between is faster since it
jumps straight to the right code -- ben
*/
if(videoPrivate.depth == 1) {
if (value & 1) {
rowbase[h >> 3] |= (128 >> (h & 7));
} else {
rowbase[h >> 3] &= ~(128 >> (h & 7));
}
} else if(videoPrivate.depth == 2) {
rowbase[h >> 2] &= (192 >> 2 * (h & 3));
rowbase[h >> 2] |= (value & 3) << 2 * (3 - (h & 3));
} else if(videoPrivate.depth == 4) {
rowbase[h >> 1] &= (h & 1) ? 0xf : 0xf0;
rowbase[h >> 1] |= (value & 15) << 4 * (1 - (h & 1));
} else if(videoPrivate.depth == 8) {
rowbase[h] = value;
} else if(videoPrivate.depth == 16) {
((u_short *) rowbase)[h] = value;
} else if(videoPrivate.depth == 32) {
/* ouch??? this doesn't work? */
((u_long *) rowbase)[h] = value;
} else {
if (value & 1) {
rowbase[h >> 3] |= (128 >> (h & 7));
} else {
rowbase[h >> 3] &= ~(128 >> (h & 7));
}
}
}
/* this should be in assembly...duh */
void vscrollup(short pixels) {
long offset,total;
long *base,*oldbase;
long oldrow;
total = (videoPrivate.height - pixels) * videoPrivate.rowbytes;
base = (long *) videoPrivate.baseaddr;
oldrow = pixels * videoPrivate.rowbytes;
oldbase = (long *)(videoPrivate.baseaddr + oldrow);
--base;
--oldbase;
for(offset = 0; offset < total; offset += 4) {
*(++base) = *(++oldbase);
}
if(videoPrivate.depth == 8) {
for(offset = 0; offset < oldrow; offset += 4) {
*(++base) = 0xFFFFFFFF;
}
} else {
for(offset = 0; offset < oldrow; offset += 4) {
*(++base) = 0L;
}
}
}
char vgetdepth(void) {
return videoPrivate.depth;
}
short vgetwidth(void) {
return videoPrivate.width;
}
short vgetheight(void) {
return videoPrivate.height;
}